import Axios from "axios";

const myAxios = {}

myAxios.install = function (Vue) {

    const MyAxiosObj = Axios.create({
        baseURL: 'http://127.0.0.1:8888/api/private/v1'
    });
    // 添加请求拦截器
    MyAxiosObj.interceptors.request.use(function (config) {
        // 在发送请求之前做些什么
        if(config.url !== '/login'){
            //登录之后才能获取token
            const token = JSON.parse(localStorage.getItem('userinfo')).token
            config.headers.Authorization = token
        }
        return config;
    });
    Vue.prototype.$req = MyAxiosObj
}
export default myAxios